<?php

/**
 * @package Nina
 * @author Andrew Rose <rose.andrew@gmail.com>, John Main <john@thedaddy.org>
 */
// include interface
require_once realpath(dirname(__FILE__)) . '.php';

class Nina_Autoloader_Nina implements Nina_Autoloader
{
	protected $path;
	
	public function __construct($path = NINA_ROOT) {
		$this->path = $path;
	}
	
	public function register() {
		spl_autoload_register(array($this, 'loader'));
	}

	public function loader($className) {
		$model_file = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
		$controller_file = $this->path . DIRECTORY_SEPARATOR . $className . '.php';

		if (file_exists($model_file)) {
			require_once $model_file;
		}
		elseif(file_exists($controller_file)) {
			require_once $controller_file;
		}
	}
}
